package org.cwnuit.train.service;

import java.util.ArrayList;
import java.util.List;

import org.cwnuit.train.dao.TrainsDAO;
import org.cwnuit.train.domain.Trains;
import org.cwnuit.train.utils.PageModel;

@SuppressWarnings("all")
public class TrainsService {
	TrainsDAO trainsDAO = new TrainsDAO();

	//添加火车站信息
	public boolean addTrain(String SQL) {
		return trainsDAO.addTrain(SQL);
	}
	
	//修改火车站信息
	public boolean updateTrain(String SQL) {
		return trainsDAO.updateTrain(SQL);
	}
	
	//删除火车站信息
	public boolean deleteTrain(String SQL) {
		return trainsDAO.deleteTrain(SQL);
	}
	
	//查询所有火车站信息
	public List<Trains> findTrains(String SQL) {
		return trainsDAO.findTrains(SQL);
	}
	
	//查询火车站信息
	public Trains findTrain(String SQL) {
		return trainsDAO.findTrain(SQL);
	}
	
	
	//分页查询火车站信息
	public PageModel findByPage(int offset, int pagesize, String SQL) {
		return trainsDAO.findByPage(offset, pagesize, SQL);
	}
	
	//查询会员信息并导出为Excel
	public List findTrainsToExcel(List<Trains> trains) {
		
		List content = new ArrayList();//全部内容
		List title = new ArrayList();//Excel标题
		title.add("车站信息导出");
		List column = new ArrayList();//Excel列明
		String header[] = { "车站编号","车站名称","车站联系人","联系人电话"};
		for(int i = 0 ;i<header.length;i++)
		{
			column.add(header[i]);
		}
		content.add(title);
		content.add(column);
		
		for (Trains train : trains) {
			List data = new ArrayList();//查询内容
			data.add(train.getTid());
			data.add(train.getTname());
			data.add(train.getTman());
			data.add(train.getTphone());
			content.add(data);
		}
		return content;
	}


}
